package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.CustomerMapper;
import cn.wolfcode.crm.mapper.CustomerTraceHistoryMapper;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.ICustomerTraceHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerTraceHistoryServiceImpl implements ICustomerTraceHistoryService {

    @Autowired
    private CustomerTraceHistoryMapper customerTraceHistoryMapper;
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public PageInfo query(QueryObject qo) {
        //传入当前页,以及每页显示条数
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<CustomerTraceHistory> list = customerTraceHistoryMapper.selectForList(qo);
        return new PageInfo(list);
    }
    @Override
    public void save(CustomerTraceHistory customerTraceHistory) {
        Long customerId = customerTraceHistory.getCustomer().getId();
        Customer customer = customerMapper.selectByPrimaryKey(customerId);
        customerTraceHistory.setInputUser(customer.getInputUser());
        customerTraceHistory.setInputTime(customer.getInputTime());
        customerTraceHistoryMapper.insert(customerTraceHistory);
    }
    @Override
    public void update(CustomerTraceHistory customerTraceHistory) {
        customerTraceHistoryMapper.updateByPrimaryKey(customerTraceHistory);
    }
    @Override
    public CustomerTraceHistory get(Long id) {
        return customerTraceHistoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CustomerTraceHistory> list() {
        return customerTraceHistoryMapper.selectAll();
    }
}
